<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <title>minid.compiler</title>
  <link href="./css/style.css" rel="stylesheet" type="text/css"/>
  <!-- <link href="./img/icon.png" rel="icon" type="image/png"/> -->
  <script type="text/javascript" src="./js/jquery.js"></script>
  <script type="text/javascript" src="./js/modules.js"></script>
  <script type="text/javascript" src="./js/quicksearch.js"></script>
  <script type="text/javascript" src="./js/navigation.js"></script>
  <!--<script type="text/javascript" src="./js/jquery.treeview.js"></script>-->
  <script type="text/javascript">
    var g_moduleFQN = "minid.compiler";
  </script>
  
</head>
<body>
<div id="content">
  <h1><a href="./htmlsrc/minid.compiler.html" class="symbol">minid.compiler</a></h1>
  
<p class="sec_header">License:</p>Copyright (c) 2008 Jarrett Billingsley
<p class="bl"/>
This software is provided 'as-is', without any express or implied warranty.
In no event will the authors be held liable for any damages arising from the
use of this software.
<p class="bl"/>
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it freely,
subject to the following restrictions:
<p class="bl"/>
    1. The origin of this software must not be misrepresented; you must not
	claim that you wrote the original software. If you use this software in a
	product, an acknowledgment in the product documentation would be
	appreciated but is not required.
<p class="bl"/>
    2. Altered source versions must be plainly marked as such, and must not
	be misrepresented as being the original software.
<p class="bl"/>
    3. This notice may not be removed or altered from any source distribution.
<dl>
<dt class="decl">class <a class="symbol _class" name="Compiler" href="./htmlsrc/minid.compiler.html#L45" kind="class" beg="45" end="372">Compiler</a> : ICompiler; <span class="attrs">[<span class="stc">scope</span>]</span> <a title="Permalink to this symbol" href="#Compiler" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L45">#</a></dt>
<dd class="ddef">
<div class="summary">This class encapsulates all the functionality needed for compiling MiniD code.</div>
<dl>
<dt class="decl"><a class="symbol _enum" name="Compiler.enum" href="./htmlsrc/minid.compiler.html#L52" kind="enum" beg="52" end="78">enum</a>; <a title="Permalink to this symbol" href="#Compiler.enum" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L52">#</a></dt>
<dd class="ddef">
<div class="summary">An enumeration of flags that can be passed to the compiler to change its behavior.</div>
<dl>
<dt class="decl"><a class="symbol _enummem" name="Compiler.enum.None" href="./htmlsrc/minid.compiler.html#L57" kind="enummem" beg="57" end="57">None</a> <a title="Permalink to this symbol" href="#Compiler.enum.None" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L57">#</a></dt>
<dd class="ddef">
<div class="summary">Do not generate code for any optional features.</div></dd>
<dt class="decl"><a class="symbol _enummem" name="Compiler.enum.TypeConstraints" href="./htmlsrc/minid.compiler.html#L62" kind="enummem" beg="62" end="62">TypeConstraints</a> <a title="Permalink to this symbol" href="#Compiler.enum.TypeConstraints" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L62">#</a></dt>
<dd class="ddef">
<div class="summary">Generate code to check parameter type constraints.</div></dd>
<dt class="decl"><a class="symbol _enummem" name="Compiler.enum.Asserts" href="./htmlsrc/minid.compiler.html#L67" kind="enummem" beg="67" end="67">Asserts</a> <a title="Permalink to this symbol" href="#Compiler.enum.Asserts" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L67">#</a></dt>
<dd class="ddef">
<div class="summary">Generate code for assert statements.</div></dd>
<dt class="decl"><a class="symbol _enummem" name="Compiler.enum.Debug" href="./htmlsrc/minid.compiler.html#L72" kind="enummem" beg="72" end="72">Debug</a> <a title="Permalink to this symbol" href="#Compiler.enum.Debug" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L72">#</a></dt>
<dd class="ddef">
<div class="summary">Generate debug info.  Currently always on.</div></dd>
<dt class="decl"><a class="symbol _enummem" name="Compiler.enum.All" href="./htmlsrc/minid.compiler.html#L77" kind="enummem" beg="77" end="77">All</a> <a title="Permalink to this symbol" href="#Compiler.enum.All" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L77">#</a></dt>
<dd class="ddef">
<div class="summary">Generate code for all optional features.</div></dd></dl></dd>
<dt class="decl">MDThread* <a class="symbol _variable" name="Compiler.t" href="./htmlsrc/minid.compiler.html#L80" kind="variable" beg="80" end="80">t</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.t" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L80">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">uint <a class="symbol _variable" name="Compiler.mFlags" href="./htmlsrc/minid.compiler.html#L81" kind="variable" beg="81" end="81">mFlags</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.mFlags" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L81">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">bool <a class="symbol _variable" name="Compiler.mIsEof" href="./htmlsrc/minid.compiler.html#L82" kind="variable" beg="82" end="82">mIsEof</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.mIsEof" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L82">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">bool <a class="symbol _variable" name="Compiler.mIsLoneStmt" href="./htmlsrc/minid.compiler.html#L83" kind="variable" beg="83" end="83">mIsLoneStmt</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.mIsLoneStmt" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L83">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">Lexer <a class="symbol _variable" name="Compiler.mLexer" href="./htmlsrc/minid.compiler.html#L84" kind="variable" beg="84" end="84">mLexer</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.mLexer" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L84">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">Parser <a class="symbol _variable" name="Compiler.mParser" href="./htmlsrc/minid.compiler.html#L85" kind="variable" beg="85" end="85">mParser</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.mParser" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L85">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">word <a class="symbol _variable" name="Compiler.mStringTab" href="./htmlsrc/minid.compiler.html#L86" kind="variable" beg="86" end="86">mStringTab</a>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.mStringTab" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L86">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl"><a class="symbol _ctor" name="Compiler.this" href="./htmlsrc/minid.compiler.html#L101" kind="ctor" beg="101" end="107">this</a><span class="params">(MDThread* <em>t</em>, uint <em>flags</em> = All)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#Compiler.this" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L101">#</a></dt>
<dd class="ddef">
<div class="summary">Constructs a compiler.  The given thread will be used to hold temporary data structures,
	to throw exceptions, and to return the functions that result from compilation.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>t</em></td><td>The thread with which this compiler will be associated.</td></tr>
<tr><td><em>flags</em></td><td>A bitwise or of any code-generation flags you want to use for this compiler.
			Defaults to All.</td></tr></table></dd>
<dt class="decl"><a class="symbol _dtor" name="Compiler.~this" href="./htmlsrc/minid.compiler.html#L109" kind="dtor" beg="109" end="121">~this</a>(); <a title="Permalink to this symbol" href="#Compiler.~this" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L109">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="Compiler.setFlags" href="./htmlsrc/minid.compiler.html#L126" kind="function" beg="126" end="129">setFlags</a><span class="params">(uint <em>flags</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#Compiler.setFlags" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L126">#</a></dt>
<dd class="ddef">
<div class="summary">Set the compiler's code-generation flags.</div></dd>
<dt class="decl">bool <a class="symbol _function" name="Compiler.asserts" href="./htmlsrc/minid.compiler.html#L134" kind="function" beg="134" end="137">asserts</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.asserts" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L134">#</a></dt>
<dd class="ddef">
<div class="summary">Returns whether or not code for asserts should be generated.</div></dd>
<dt class="decl">bool <a class="symbol _function" name="Compiler.typeConstraints" href="./htmlsrc/minid.compiler.html#L142" kind="function" beg="142" end="145">typeConstraints</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.typeConstraints" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L142">#</a></dt>
<dd class="ddef">
<div class="summary">Returns whether or not code for parameter type constraint checking should be generated.</div></dd>
<dt class="decl">bool <a class="symbol _function" name="Compiler.isEof" href="./htmlsrc/minid.compiler.html#L168" kind="function" beg="168" end="171">isEof</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.isEof" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L168">#</a></dt>
<dd class="ddef">
<div class="summary">Returns whether or not the most recently-thrown exception was thrown due to an unexpected end-of-file.
	As an example, this is used by MDCL (that is, minid.commandline) to detect when more code must be entered
	to complete a code segment.  A simple example of use:
	
<pre class="d_code">
<span class="k">scope</span> <span class="i">c</span> = <span class="k">new</span> <span class="i">Compiler</span>(<span class="i">t</span>);

<span class="k">try</span>
	<span class="i">c</span>.<span class="i">compileExpression</span>(<span class="i">someCode</span>, <span class="sl">"test"</span>);
<span class="k">catch</span>(<span class="i">MDException</span> <span class="i">e</span>)
{
	<span class="k">auto</span> <span class="i">ex</span> = <span class="i">catchException</span>(<span class="i">t</span>);
	
	<span class="k">if</span>(<span class="i">c</span>.<span class="i">isEof</span>())
	{
		<span class="lc">// error was caused by an unexpected end-of-file</span>
	}
}
</pre></div></dd>
<dt class="decl">bool <a class="symbol _function" name="Compiler.isLoneStmt" href="./htmlsrc/minid.compiler.html#L177" kind="function" beg="177" end="180">isLoneStmt</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.isLoneStmt" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L177">#</a></dt>
<dd class="ddef">
<div class="summary">Returns whether or not the most recently-thrown exception was thrown due to a no-effect expression being used
	as a statement (yes, this method has a horrible name).  Its use is identical to isEof().</div></dd>
<dt class="decl">void <a class="symbol _function" name="Compiler.exception" href="./htmlsrc/minid.compiler.html#L182" kind="function" beg="182" end="185">exception</a><span class="params">(ref CompileLoc <em>loc</em>, char[] <em>msg</em>, ...)</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.exception" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L182">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="Compiler.eofException" href="./htmlsrc/minid.compiler.html#L187" kind="function" beg="187" end="191">eofException</a><span class="params">(ref CompileLoc <em>loc</em>, char[] <em>msg</em>, ...)</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.eofException" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L187">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">void <a class="symbol _function" name="Compiler.loneStmtException" href="./htmlsrc/minid.compiler.html#L193" kind="function" beg="193" end="197">loneStmtException</a><span class="params">(ref CompileLoc <em>loc</em>, char[] <em>msg</em>, ...)</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.loneStmtException" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L193">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">MDThread* <a class="symbol _function" name="Compiler.thread" href="./htmlsrc/minid.compiler.html#L199" kind="function" beg="199" end="202">thread</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.thread" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L199">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">Allocator* <a class="symbol _function" name="Compiler.alloc" href="./htmlsrc/minid.compiler.html#L204" kind="function" beg="204" end="207">alloc</a><span class="params">()</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.alloc" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L204">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">char[] <a class="symbol _function" name="Compiler.newString" href="./htmlsrc/minid.compiler.html#L209" kind="function" beg="209" end="216">newString</a><span class="params">(char[] <em>data</em>)</span>; <span class="attrs">[<span class="prot">public</span>, <span class="stc">override</span>]</span> <a title="Permalink to this symbol" href="#Compiler.newString" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L209">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">word <a class="symbol _function" name="Compiler.compileModule" href="./htmlsrc/minid.compiler.html#L234" kind="function" beg="234" end="244">compileModule</a><span class="params">(char[] <em>filename</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#Compiler.compileModule" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L234">#</a></dt>
<dd class="ddef">
<div class="summary">Compile a source code file into a function closure.  Takes the path to the source file, compiles
	that file, and pushes the top-level closure onto the stack.  The environment of the closure is
	just set to the global namespace of the compiler's thread; you must create and set a namespace
	for the module function before calling it.</div>
You shouldn't have to deal with this function that much.  Most of the time the compilation of
	modules should be handled for you by the import system.
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>filename</em></td><td>The filename of the source file to compile.</td></tr></table>
<p class="sec_header">Returns:</p>The stack index of the newly-pushed function closure that represents the top-level function
		of the module.</dd>
<dt class="decl">word <a class="symbol _function" name="Compiler.compileModule:2" href="./htmlsrc/minid.compiler.html#L258" kind="function" beg="258" end="271">compileModule</a><span class="params">(char[] <em>source</em>, char[] <em>name</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#Compiler.compileModule:2" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L258">#</a></dt>
<dd class="ddef">
<div class="summary">Same as above, but compiles from a string holding the source rather than from a file.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>source</em></td><td>The source code as a string.</td></tr>
<tr><td><em>name</em></td><td>The name which should be used as the source name in compiler error message.  Takes the
			place of the filename when compiling from a source file.</td></tr></table>
<p class="sec_header">Returns:</p>The stack index of the newly-pushed function closure that represents the top-level function
		of the module.</dd>
<dt class="decl">word <a class="symbol _function" name="Compiler.compileStatements" href="./htmlsrc/minid.compiler.html#L284" kind="function" beg="284" end="297">compileStatements</a><span class="params">(char[] <em>source</em>, char[] <em>name</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#Compiler.compileStatements" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L284">#</a></dt>
<dd class="ddef">
<div class="summary">Compile a list of statements into a function which takes a variadic number of arguments.  The environment
	of the compiled function closure is set to the globals of the compiler's thread.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>source</em></td><td>The source code as a string.</td></tr>
<tr><td><em>name</em></td><td>The name to use as the source name for compilation errors.</td></tr></table>
<p class="sec_header">Returns:</p>The stack index of the newly-pushed function closure.</dd>
<dt class="decl">word <a class="symbol _function" name="Compiler.compileExpression" href="./htmlsrc/minid.compiler.html#L309" kind="function" beg="309" end="322">compileExpression</a><span class="params">(char[] <em>source</em>, char[] <em>name</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#Compiler.compileExpression" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L309">#</a></dt>
<dd class="ddef">
<div class="summary">Compile a single expression into a function which returns the value of that expression when called.</div>
<p class="sec_header">Params:</p>
<table class="params">
<tr><td><em>source</em></td><td>The source code as a string.</td></tr>
<tr><td><em>name</em></td><td>The name to use as the source name for compilation errors.</td></tr></table>
<p class="sec_header">Returns:</p>The stack index of the newly-pushed function closure.</dd>
<dt class="decl">word <a class="symbol _function" name="Compiler.loadJSON" href="./htmlsrc/minid.compiler.html#L328" kind="function" beg="328" end="343">loadJSON</a><span class="params">(char[] <em>source</em>)</span>; <span class="attrs">[<span class="prot">public</span>]</span> <a title="Permalink to this symbol" href="#Compiler.loadJSON" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L328">#</a></dt>
<dd class="ddef">
<div class="summary">Parses a JSON string into a MiniD value, pushes that value onto the stack, and returns the
	index of the newly-pushed value.</div></dd>
<dt class="decl">void <a class="symbol _function" name="Compiler.vexception" href="./htmlsrc/minid.compiler.html#L349" kind="function" beg="349" end="356">vexception</a><span class="params">(ref CompileLoc <em>loc</em>, char[] <em>msg</em>, TypeInfo[] <em>arguments</em>, va_list <em>argptr</em>)</span>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.vexception" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L349">#</a></dt>
<dd class="ddef"></dd>
<dt class="decl">word <a class="symbol _function" name="Compiler.commonCompile" href="./htmlsrc/minid.compiler.html#L358" kind="function" beg="358" end="371">commonCompile</a><span class="params">(void delegate() <em>dg</em>)</span>; <span class="attrs">[<span class="prot">private</span>]</span> <a title="Permalink to this symbol" href="#Compiler.commonCompile" class="symlink">¶</a><a title="Go to the HTML source file" class="srclink" href="./htmlsrc/minid.compiler.html#L358">#</a></dt>
<dd class="ddef"></dd></dl></dd></dl>
</div>
<div id="footer">
  <p></p>
  <p>Page generated by <a href="http://code.google.com/p/dil">dil</a> on Fri Dec 26 03:29:19 2008. Rendered by <a href="http://code.google.com/p/dil/wiki/Kandil">kandil</a>.</p>
</div>
</body>
</html>